home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / ADA / GNAT / !gcc / adainc / 2 / adb / a-ticoau < prev    next >
Text File  |  1996-02-12  |  7KB  |  206 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --              A D A . T E X T _ I O . C O M P L E X _ A U X               --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.2 $                              --
  10. --                                                                          --
  11. --     Copyright (C) 1992,1993,1994,1995 Free Software Foundation, Inc.     --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
  37. with Ada.Text_IO.Float_Aux;
  38.  
  39. with System.Img_Real; use System.Img_Real;
  40.  
  41. package body Ada.Text_IO.Complex_Aux is
  42.  
  43.    package Aux renames Ada.Text_IO.Float_Aux;
  44.  
  45.    ---------
  46.    -- Get --
  47.    ---------
  48.  
  49.    procedure Get
  50.      (File  : in  File_Type;
  51.       ItemR : out Long_Long_Float;
  52.       ItemI : out Long_Long_Float;
  53.       Width : Field)
  54.    is
  55.       Buf   : String (1 .. Field'Last);
  56.       Stop  : Integer := 0;
  57.       Ptr   : aliased Integer;
  58.       Paren : Boolean := False;
  59.  
  60.    begin
  61.       --  General note for following code, exceptions from the calls to
  62.       --  Get for components of the complex value are propagated.
  63.  
  64.       if Width /= 0 then
  65.          Load_Width (File, Width, Buf, Stop);
  66.          Gets (Buf (1 .. Stop), ItemR, ItemI, Ptr);
  67.  
  68.          for J in Ptr + 1 .. Stop loop
  69.             if not Is_Blank (Buf (J)) then
  70.                raise Data_Error;
  71.             end if;
  72.          end loop;
  73.  
  74.       --  Case of width = 0
  75.  
  76.       else
  77.          Load_Skip (File);
  78.          Load (File, Buf, Ptr, '(', Paren);
  79.          Aux.Get (File, ItemR, 0);
  80.          Load_Skip (File);
  81.          Load (File, Buf, Ptr, ',');
  82.          Aux.Get (File, ItemI, 0);
  83.  
  84.          if Paren then
  85.             Load_Skip (File);
  86.             Load (File, Buf, Ptr, ')', Paren);
  87.  
  88.             if not Paren then
  89.                raise Data_Error;
  90.             end if;
  91.          end if;
  92.       end if;
  93.    end Get;
  94.  
  95.    ----------
  96.    -- Gets --
  97.    ----------
  98.  
  99.    procedure Gets
  100.      (From  : in  String;
  101.       ItemR : out Long_Long_Float;
  102.       ItemI : out Long_Long_Float;
  103.       Last  : out Positive)
  104.    is
  105.       Paren : Boolean;
  106.       Pos   : Integer;
  107.  
  108.    begin
  109.       String_Skip (From, Pos);
  110.  
  111.       if From (Pos) = '(' then
  112.          Pos := Pos + 1;
  113.          Paren := True;
  114.       else
  115.          Paren := False;
  116.       end if;
  117.  
  118.       Aux.Gets (From, ItemR, Pos);
  119.  
  120.       String_Skip (From (Pos + 1 .. From'Last), Pos);
  121.  
  122.       if From (Pos) = ',' then
  123.          Pos := Pos + 1;
  124.       end if;
  125.  
  126.       Aux.Gets (From (Pos + 1 .. From'Last), ItemI, Pos);
  127.  
  128.       if Paren then
  129.          String_Skip (From (Pos + 1 .. From'Last), Pos);
  130.  
  131.          if From (Pos) /= ')' then
  132.             raise Data_Error;
  133.          end if;
  134.       end if;
  135.  
  136.       Last := Pos;
  137.    end Gets;
  138.  
  139.    ---------
  140.    -- Put --
  141.    ---------
  142.  
  143.    procedure Put
  144.      (File  : File_Type;
  145.       ItemR : Long_Long_Float;
  146.       ItemI : Long_Long_Float;
  147.       Fore  : Field;
  148.       Aft   : Field;
  149.       Exp   : Field)
  150.    is
  151.    begin
  152.       Put (File, '(');
  153.       Aux.Put (File, ItemR, Fore, Aft, Exp);
  154.       Put (File, ',');
  155.       Aux.Put (File, ItemI, Fore, Aft, Exp);
  156.       Put (File, ')');
  157.    end Put;
  158.  
  159.    ----------
  160.    -- Puts --
  161.    ----------
  162.  
  163.    procedure Puts
  164.      (To    : out String;
  165.       ItemR : Long_Long_Float;
  166.       ItemI : Long_Long_Float;
  167.       Aft   : in  Field;
  168.       Exp   : in  Field)
  169.    is
  170.       I_String : String (1 .. 3 * Field'Last);
  171.       R_String : String (1 .. 3 * Field'Last);
  172.  
  173.       Iptr : Natural;
  174.       Rptr : Natural;
  175.  
  176.    begin
  177.       --  Both parts are initially converted with a Fore of 0
  178.  
  179.       Rptr := 0;
  180.       Set_Image_Real (ItemR, R_String, Rptr, 0, Aft, Exp);
  181.       Iptr := 0;
  182.       Set_Image_Real (ItemI, I_String, Iptr, 0, Aft, Exp);
  183.  
  184.       --  Check room for both parts plus parens plus comma (RM G.1.3(34))
  185.  
  186.       if Rptr + Iptr + 3 > To'Length then
  187.          raise Layout_Error;
  188.       end if;
  189.  
  190.       --  If there is room, layout result according to (RM G.1.3(31-33))
  191.  
  192.       To (To'First) := '(';
  193.       To (To'First + 1 .. To'First + Rptr) := R_String (1 .. Rptr);
  194.       To (To'First + Rptr + 1) := ',';
  195.  
  196.       To (To'Last) := ')';
  197.       To (To'Last - Iptr .. To'Last - 1) := I_String (1 .. Iptr);
  198.  
  199.       for J in To'First + Rptr + 2 .. To'Last - Iptr - 1 loop
  200.          To (J) := ' ';
  201.       end loop;
  202.  
  203.    end Puts;
  204.  
  205. end Ada.Text_IO.Complex_Aux;
  206.